package test.yzx.pproject.act1;

import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import test.yzx.pproject.R;
import test.yzx.pproject.ViewAnimatorUtil;

public class ArgbAnimActivity extends AppCompatActivity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.argb_);

        final View layout = findViewById(R.id.layout);
        final int startColor = Color.parseColor("#ff0000");
        final int endColor = Color.parseColor("#000000");
        final ArgbEvaluator ae = new ArgbEvaluator();

        ValueAnimator anim = (ValueAnimator) ViewAnimatorUtil.make(1500, 0, null, new ViewAnimatorUtil.SimpleValueCallback(){
            public void onUpdate(Animator animation, float value) {
                int color = (int) ae.evaluate(value, startColor, endColor);
                layout.setBackgroundColor(color);
            }
        }, 0, 1f);
        anim.setRepeatMode(ValueAnimator.REVERSE);
        anim.setRepeatCount(Integer.MAX_VALUE);
        anim.start();

    }

}
